/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.edu.thptduongbachmai.DbUtil;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Son
 */
public class Criteria {

    List<SimpleExpression> list;
    Order order;
    Projections projections;
    long firstResult=-1;
    int maxResults;

    public Criteria() {
        list = new ArrayList<SimpleExpression>();
    }
    public void setFirstResult(long i)
    {
        firstResult = i;
    }
    public  void setMaxResults(int i)
    {
        maxResults = i;
    }
    public void add(SimpleExpression se) {
        list.add(se);
    }

    public void addOther(Order order) {
        this.order = order;
    }

    public void setProjection(Projections prjctn) {
        projections = prjctn;
    }

    public Projections getProjection() {
        return projections;
    }

    @Override
    public String toString() {
        int i = 0;
        String result = "";
        for (SimpleExpression simpleExpression : list) {
            if (i > 0) {
                result += " and " + simpleExpression.toString();
            } else {
                result += " where " + simpleExpression.toString();
            }
            i++;
        }
        if (order != null) {
            result += " " + order.toString();
        }
        if (firstResult > -1 && maxResults > -1)
        {
            result += " limit "+firstResult+","+maxResults;
        }
        return result;
    }
}
